public class SquareNumber {
    public static void main(String[] args) {
        int[] numbersToTest = {3, 9, 27, 45, 99, 100, 35, 49};
        for (int i : numbersToTest) {
            System.out.println("Is it (" + String.format("%3s",i) + ") a square? : " + isSquare(i));
        }
    }

    /*
        Write a program to find whether a given number is a perfect square or not.
        You can only use addition and subtraction operation to find a solution with min. complexity.

        i/p : 25
        o/p : True

        i/p : 44
        o/p: False
     */
    private static boolean isSquare(int number) {
        if (number < 0) return false;// Negative integers are not squares
        if (number < 2) return true; // 0 and 1 cases
        int oddCounter = 0;
        while (number > 0) {
            int oddNumber = oddCounter + oddCounter + 1;
            number -= oddNumber;
            oddCounter++;
        }
        return number == 0;
    }
}
